package org.wyw.solution;

import org.wyw.entiry.TreeNode;

import java.util.ArrayList;
import java.util.List;

@Solution(
        id = 1,
        title = "二叉树中序遍历",
        difficulty = "medium",
        link = "https://leetcode.cn/problems/binary-tree-inorder-traversal/description/"
)
public class Solution010 {

    /**
     * 思路：递归实现
     * 中序遍历：左子树——根节点——右子树
     */
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        inorder(root ,  list);
        return list;
    }

    private void inorder(TreeNode node , List<Integer> list){
        if (node == null) return;
        inorder(node.left,list);
        list.add(node.val);
        inorder(node.right,list);
    }
}
